home *** CD-ROM | disk | FTP | other *** search
- #APP
-
- # alloca(size) allocate junk in stack frame
- #
- # void *alloca(size_t size)
- # this version for minix checks brksize
- #
- # ++jrb bammi@dsrgsun.ces.cwru.edu
- #
- .text
- .even
- .globl _brksize
- .globl _alloca
- slush = 32 | desired slush below brksize
- _alloca:
- movel sp@+,a0 | get return addr
- movel sp@+,d0 | get size
-
- addql #1,d0 | ensure address even
- andb #0xfe,d0 | lop off extra bits
-
- movel sp,a1 | save old sp in case we fail
- subl d0,sp | increase stack frame size by that much
- movel sp,d0 | set up to return it
-
- moveq #slush,d1 | check against brk
- addl _brksize,d1
- cmpl d1,d0
- bles outofstack | not enough stack
-
- retn: lea sp@(-4),sp | new top of stack (caller pops this)
-
- jmp a0@ | return by jmping via saved addr
-
- outofstack:
- movel a1,sp | restore saved sp
- moveq #0,d0 | NULL return val
- bras retn
-